package httpclient;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.URL;

public class HttpPostImpl2 {

	public static void main(String[] args) throws Exception{

		Socket socket = new Socket("127.0.0.1", 8080);
		OutputStream os = socket.getOutputStream();
		
		String content = "name=admin&password=admin1";
		
		StringBuilder sb = new StringBuilder();
		sb.append("POST /web/b.jsp HTTP/1.1" + "\r\n");
		sb.append("Host: localhost:8080" + "\r\n");		
		sb.append("Content-Type: application/x-www-form-urlencoded" + "\r\n");
		sb.append("Content-Length: " + content.length() + "\r\n");
		sb.append("\r\n");
		sb.append(content + "\r\n");
		
		os.write(sb.toString().getBytes());
		
		
		
		InputStream is = socket.getInputStream();
		BufferedReader br = new BufferedReader(new InputStreamReader(is, "utf-8"));
		String s;
		while ((s = br.readLine()) != null) {
			System.out.print(s);
			System.out.println();
		}

		socket.close();
	}
}
